package com.kunbo.cn.app.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.kunbo.cn.app.entity.AppUser;
import com.kunbo.cn.app.service.TransportUnitService;
import com.kunbo.cn.util.date.SDate;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.ResultBean;

/**
 *客户App运输单位管理
 * @author bjl  
 * @date 2019年3月28日 
 */
@RestController
@RequestMapping("/transport")
public class TransportUnitController {
	@Autowired
	private TransportUnitService Service;
	/**
	 * 新增运输单位
	 * 
	 */
	@PostMapping("/add")
	public CommonResult add(AppUser tunit) {
		Service.save(tunit);
		return new CommonResult(true,"操作成功",null);
	}
	/**
	 * 获取客户名称
	 * @param login_nameke客户登录账号
	 * @return
	 */
	@GetMapping("/getTitle")
	public String getTitle(
			@RequestParam("login_name")String login_name
			){
		return Service.getTitle(login_name);
	}
	@GetMapping("/createCode")
	public String createCode(){
		Map<String,Object> map=new HashMap<String,Object>();
		 String prex = "YS";
		 String noticeCode= prex+SDate.getSystemDateYMDHMSToString();
		return noticeCode;
	}
	/**
	 * 客户app运输单位列表
	 * 
	 */
	@GetMapping("/List")
	public ResultBean<List<Map<String,Object>>> TransportList(
			@RequestParam("login_name")String login_name,
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>>  result =  new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", Service.TransportList(login_name, page,pageSize));
	}
	/**
	 * 客户app运输单位详情
	 * 
	 */
	@GetMapping("/details")
	public ResultBean<List<Map<String,Object>>> TransDetails(
			@RequestParam("id")Integer id
			){
		ResultBean<List<Map<String,Object>>>  result =  new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", Service.TransDetails(id));
	}
	@DeleteMapping("/delete")
	public CommonResult delete(Integer id) {
		Service.delete(id);
		return new CommonResult(true,"操作成功",null);
	}
	
	
}
